
package com.example.demo.repository;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.example.demo.pojo.User;

// 继承JpaRepository完成对数据库的操作 
public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {

	//定位用户
	User findUserById(long id);
	
	//@Transactional
	void deleteById(long id);
	
	@Query(name = "findUserBylastName", nativeQuery = true, value = "select *from User where lastName=:lastName")
	List<User> findUserBylastName(@Param("lastName") String lastName);

	@Query(value = "select tu from tbl_user tu where tu.id = :id", nativeQuery = true)
	Page<User> selectAllByUserId(@Param("id") Long id, Pageable pageable);


}
